<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>



<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.08">
<LINK rel="stylesheet" type="text/css" href="embroot.css">
<TITLE>
Foreign C Interface
</TITLE>
</HEAD>
<BODY >
<A HREF="embroot073.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="embroot085.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>

<H1 CLASS="chapter"><A NAME="htoc149">Appendix&nbsp;D</A>&nbsp;&nbsp;Foreign C Interface</H1>

<A NAME="libforeign"></A>
<A NAME="@default403"></A>
<A NAME="@default404"></A>
This library (loaded with <TT>:- lib(foreign)</TT>)
allows to use external functions written
for Quintus or SICStus Prolog, or to interface
C functions which are independent of ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP>.
It accepts the syntax and semantics of the
predicates <A HREF="../bips/lib/foreign/index.html"><B>foreign/3</B></A><A NAME="@default405"></A>, <A HREF="../bips/lib/foreign/index.html"><B>load_foreign_files/2</B></A><A NAME="@default406"></A> and <A HREF="../bips/lib/foreign/index.html"><B>load_foreign_files/2</B></A><A NAME="@default407"></A>
of Quintus/SICStus.
Since their external interface is incompatible with the ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> one,
this library generates a C source file which converts the ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP>interface into the foreign one, by defining a new C function
for every C function defined in the foreign interface.
Note that this approach uses more C code, but it is still more efficient
than using a generic procedure to check the argument
of every external function.<BR>
<BR>
After compiling definitions of the <B>foreign/3</B> predicate,
(the predicate <B>foreign_file/2</B> is ignored),
the predicate <B>make_simple_interface</B> has to be called.
This predicate generates a file <I>interface.c</I>, which contains
the auxiliary C definitions.
This file has to be compiled to obtain the <I>interface.o</I> file,
it might also have to be edited to include other <I>.h</I> files.
After the file <I>interface.o</I> has been generated,
the system is fully compatible with the Quintus/SICStus foreign
interface, and calling <B>load_foreign_files/2</B> will connect
the external functions with ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP>.<BR>
<BR>
Although it is possible to use this library to interface
existing independent C functions, its main use is to
port foreign interface from Quintus or SICStus.
Please refer to their manuals for the description of the
foreign interface.<BR>
<BR>
<BR>
<BR>
<HR>
<A HREF="embroot073.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="embroot085.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>
